package com.example.footballsystem.controller;

import com.example.footballsystem.entity.Comment;
import com.example.footballsystem.entity.News;
import com.example.footballsystem.entity.Post;
import com.example.footballsystem.service.PostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/Post")
@CrossOrigin(origins = "*")
public class PostController {
    @Autowired
    PostService postService;
    @PostMapping("/addPost")
    public ResponseEntity<Boolean> addPost(@RequestBody Post post){
        return ResponseEntity.ok().body(postService.addNew(post));
    }
    @PostMapping("/getAllPost")
    public ResponseEntity<List<Post>> getAllPost(String account){
        return ResponseEntity.ok().body(postService.getAllPost(account));
    }
    @PostMapping("/deletePost")
    public ResponseEntity<Boolean> deletePost(@RequestBody List<Post> post){
        for (Post post1 : post) {
            postService.deleteNew(post1);
        }
        return ResponseEntity.ok().body(true);
    }
    @GetMapping("/searchPost")
    public ResponseEntity<List<Post>> searchNews(String info){
        log.info("123"+info);
        return ResponseEntity.ok().body(postService.searchNews(info));
    }
    @GetMapping("/getPostByID")
    public ResponseEntity<Post> getPostByID(int id){
        return ResponseEntity.ok().body(postService.getPostByID(id));
    }
    @GetMapping("/getComment")
    public ResponseEntity<List<Comment>> getComment(int postId){
        return ResponseEntity.ok().body(postService.getCommentByPost(postId));
    }
    @PostMapping("/addComment")
    public ResponseEntity<Boolean> addComment(@RequestBody Comment comment){
        log.info("sssaa "+comment.toString());
        return ResponseEntity.ok().body(postService.addComment(comment));
    }
    @GetMapping("/getNewsCount")
    public ResponseEntity<List<Integer>> getNewsCount(){
        return ResponseEntity.ok().body(postService.getPostCount());
    }
    @GetMapping("count")
    public ResponseEntity<Integer> getCount(){
        return ResponseEntity.ok().body(postService.count());
    }
//    @GetMapping("getLike")
//    public ResponseEntity<List<Boolean>> getLike(String account){
//        return ResponseEntity.ok().body(postService.getAllLike(account));
//    }
    @GetMapping("setlike")
    public ResponseEntity<Boolean> setLike(String account,int postID,int num){
        return ResponseEntity.ok().body(postService.addLike(account,postID,num));
    }
}
